var t = require("../../@babel/runtime/helpers/interopRequireDefault")(require("../../@babel/runtime/helpers/defineProperty")), e = require("../../services/api.js"), o = require("../../utils/util.js");

function n(t, e) {
    var o = Object.keys(t);
    if (Object.getOwnPropertySymbols) {
        var n = Object.getOwnPropertySymbols(t);
        e && (n = n.filter(function(e) {
            return Object.getOwnPropertyDescriptor(t, e).enumerable;
        })), o.push.apply(o, n);
    }
    return o;
}

Page({
    data: {
        info: {}
    },
    onLoad: function(t) {},
    getGoodsDetail: function(t) {
        var o = this;
        (0, e.getGoodsDetail)({
            goods_id: t
        }).then(function(t) {
            if (200 === t.data.code) {
                var e = t.data.data;
                e.content = o.fimg(e.content), e.usage_notice = o.fimg(e.usage_notice), e.covers && (e.covers = JSON.parse(e.covers), 
                e.covers = e.covers.map(function(t) {
                    return /http/.test(t) || (t = "https://new.immqutao.com" + t), t;
                })), o.setData({
                    info: e
                });
            }
        });
    },
    fimg: function(t) {
        if (t) {
            var e = new RegExp("<img", "gi");
            return t.replace(e, '<img style="max-width:100% !important;height:auto !important;margin-top:10px;"');
        }
    },
    onReady: function() {},
    onShow: function() {
        var t = this.options;
        t.id && this.getGoodsDetail(t.id);
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    doPay: function() {
        (0, o.getAuth)() ? (wx.showLoading({
            title: "正在创建订单",
            mask: !0
        }), (0, e.createGoodsOrder)({
            goods_id: this.data.info.id
        }).then(function(o) {
            200 === o.data.code ? (0, e.createGoodsPay)({
                pay_type: 1,
                trade_type: "mini_program",
                order_group: "order",
                data: {
                    order_sn: o.data.data.o_id
                }
            }).then(function(e) {
                200 === e.data.code && wx.requestPayment(Object.assign({}, function(e) {
                    for (var o = 1; o < arguments.length; o++) {
                        var a = null != arguments[o] ? arguments[o] : {};
                        o % 2 ? n(a, !0).forEach(function(o) {
                            (0, t.default)(e, o, a[o]);
                        }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(a)) : n(a).forEach(function(t) {
                            Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(a, t));
                        });
                    }
                    return e;
                }({}, e.data.data.config), {
                    timeStamp: e.data.data.config.timeStamp || e.data.data.config.timestamp,
                    success: function() {
                        wx.hideLoading(), wx.showToast({
                            title: "支付成功",
                            mask: !0
                        }), setTimeout(function() {
                            wx.navigateTo({
                                url: "/pages/tgOrder/index"
                            });
                        }, 1e3);
                    },
                    fail: function(t) {
                        console.log(t), wx.showModal({
                            title: "提示",
                            content: "支付失败",
                            showCancel: !1
                        });
                    }
                }));
            }) : wx.showModal({
                title: "提示",
                content: o.data.message,
                showCancel: !1
            });
        })) : wx.navigateTo({
            url: "/pages/login/index"
        });
    },
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});